import camera from './camera'
import light from './light'
import background from '../objects/background'


// 场景(Scene): 场景能够让你在什么地方、摆放什么东西来交给three.js来渲染，这是你放置物体、灯光和摄像机的地方。
// 在Scene中给元素设置position就是从“物体坐标系”向“世界坐标系”的转换
class Scene {
    constructor() {
        this.instance = null
    }

    init () {
        this.instance = new THREE.Scene
        const renderer = this.renderer = new THREE.WebGLRenderer({
            canvas: canvas,
            antilias: true,
            preserveDrawingBuffer: true
        })

        renderer.shadowMap.enabled = true
        renderer.shadowMap.type = THREE.PCFShadowMap
        

        this.camera = camera
        this.light = light
        this.camera.init()
        this.light.init()

        // 用于简单模拟3个坐标轴的对象.
        // 红色代表 X 轴. 绿色代表 Y 轴. 蓝色代表 Z 轴.
        this.axesHelper = new THREE.AxesHelper(100)

        this.instance.add(this.axesHelper)
        this.instance.add(this.camera.instance)

        for(let lightType in this.light.instances) {
            this.instance.add(this.light.instances[lightType])
        }

        this.background = background
        this.background.init()
        this.background.instance.position.z = -84
        this.camera.instance.add(this.background.instance)
    }

    render () {
        this.renderer.render(this.instance, this.camera.instance)
    }
}

export default new Scene()